﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SyncLib;
using DevComponents.DotNetBar.SuperGrid;
using AppCommon;

namespace SyncConfig.Controls
{
    public partial class ServerConfig : AppCommon.Controls.UserControlBase
    {
        public ServerConfig()
        {
            InitializeComponent();
        }
        public void DataBind()
        {
            serverConfigTableAdapter1.Connection.ConnectionString = CommonVariable.SqlConnectionString;
            serverConfigTableAdapter1.Fill(syncConfigDS1.ServerConfig);
            superGridControl1.PrimaryGrid.Columns["ConfigValue"].RenderType = typeof(MyGridTextEdit);
        }

        private void ServerConfig_Load(object sender, EventArgs e)
        {

        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (superGridControl1.ActiveEditor != null)
                superGridControl1.ActiveEditor.EndEdit();
            superGridControl1.PrimaryGrid.FlushActiveRow();
            superGridControl1.PrimaryGrid.FlushSelected();
            serverConfigTableAdapter1.Update(syncConfigDS1.ServerConfig);

        }

        private class MyGridTextEdit : GridTextBoxXEditControl
        {
            public override string Text
            {
                get
                {

                    return base.Text;
                }
                set
                {
                    SyncConfigDS.ServerConfigRow current = this.EditorCell.SuperGrid.GetDataRow<SyncConfigDS.ServerConfigRow>(this.EditorCell.RowIndex);
                    if (current != null)
                        if (current.ConfigName.IndexOf("password", StringComparison.InvariantCultureIgnoreCase) >= 0)
                            PasswordChar = '*';
                        else
                            PasswordChar =Char.MinValue;
                    base.Text = value;
                }
            }
        }
    }
}
